<?php

//view of Site is in view/application folder
//content: about.php - view about page home page
//		   home.php - view home page
//		   search.php - view search results
 
class Site extends CI_Controller{
	function __construct(){
		parent::__construct();
	}
	
	//index page of site
	function index(){
		if ($this->session->userdata('logged_in')==false){
			redirect('/login');
		}
		
		$this->load->model('thesismodel');
		$data['rows'] = $this->thesismodel->getAll();
		$data['title'] = 'Home';
		$this->load->view('application/home',$data);
	}
	
	//about page
	function about(){
		if ($this->session->userdata('logged_in')==false){
			redirect('/login');
		}
		$data['title'] = 'About';
		$this->load->view('application/about',$data);
	}
	
	//search 
	function search(){
		if ($this->session->userdata('logged_in')==false){
			redirect('/login');
		}
		
		$this->load->model('thesismodel');
		$attribute = $this->input->post('attribute');
		$attribute_name = $this->input->post('attribute_name');
		switch ($attribute)
		{
			case 'name':
				$data['rows'] = $this->thesismodel->searchByName($attribute_name);
				break;
			case 'id':
				$data['rows'] = $this->thesismodel->searchById($attribute_name);
				break;
			case 'type':
				$data['rows'] = $this->thesismodel->searchByType($attribute_name);
				break;
			case 'teacher':
				$data['rows'] = $this->thesismodel->searchByTeachername($attribute_name);
				break;
		}
		$data['title'] = 'Search Result';
		
		$this->load->view('application/search',$data);
		
	}
}
?>